﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef MacroTool_h__
#define MacroTool_h__

#include <string>
#include "ResourceHelper.h"

/************************************************************************/
/* 定义一些实用的宏工具 
*/
/************************************************************************/
#define FRIEND_CLASS(T) friend class T;

#define SHARED_PTR_THIS_NODE std::dynamic_pointer_cast<Node>(shared_from_this())
#define SHARED_PTR_THIS_WIDGET std::dynamic_pointer_cast<Widget>(shared_from_this())

#define R(res_name) ResourceHelper::resourcePath(res_name)
#define _R(res_name) ResourceHelper::resourcePath(L##res_name)

#define THROW_NEED_OVERRIDE throw std::string("需要复写函数 ")+std::string(__FUNCTION__);

/***********编译相关********************************/

#define SGE_API 

/***********命名空间******************/

#define USING_NS_DX using namespace DirectX;
#define USING_NS_MW using namespace Microsoft::WRL;

/***********函数定义************************/


#define FRIEND_SMART_PTR(class_name)			\
	friend class std::shared_ptr<class_name>;	\
	friend class std::weak_ptr<class_name>;		\
	friend class std::_Ref_count_obj<class_name>;\
	friend class std::unique_ptr<class_name>;

#define UI_CLASS(class_name)													\
	protected:																	\
	static class_name* makeWidgetPtr(Widget * parent = nullptr)					\
	{																			\
		class_name * ptr = new class_name(parent);								\
		return ptr;																\
	}

#define NODE_CLASS(class_name)													\
	protected:																	\
	static class_name* makeNodePtr(Node * parent = nullptr)						\
	{																			\
		class_name * ptr = new class_name(parent);								\
		return ptr;																\
	}																			\

#define EVENT_CALSS(guid)																			\
	public:																							\
		static const std::string getEventGuid() { static std::string _guid = guid; return _guid; }	\
		const std::string  & getGuid()const override{static std::string _guid = guid; return _guid; }\
	private:																						\

#define SCENE_CLASS(class_name)   \
	public:	\
		static std::shared_ptr<class_name> create()\
		{\
			auto p = std::shared_ptr<class_name>(new class_name());  \
			if (p && p->init())\
			{\
				return p;\
			}\
			return nullptr;\
			}\
	private:\

#endif // MacroTool_h__															
